/**
 * @desc 提交成功后关闭标签回调
 * @param json
 */
function callBackCloseCurrrentPanel(json) {
	DWZ.ajaxDone(json);
	if (json.statusCode == "200") {

		navTab.closeCurrentTab(json.rel);
		var pageForm = $("#pagerForm", navTab.getPanel(json.rel));
		if (pageForm != undefined) {
			navTab.reload(pageForm.attr('action'), {
				data : pageForm.serializeArray(),
				navTabId : json.rel
			});
		}
	}
}

/**
 * 提交成功后关闭窗口回调
 * 
 * @param json
 * @return
 */
function callBackCloseWindow(json) {
	DWZ.ajaxDone(json);
	if (json.statusCode == '200') {
		$.pdialog.closeCurrent();
		navTab.reloadFlag(json.rel);
		var pageForm = $("#pagerForm", navTab.getPanel(json.rel));
		if (pageForm != undefined) {
			navTab.reload(pageForm.attr('action'), {
				data : pageForm.serializeArray(),
				navTabId : json.rel
			});
			// pageForm.submit();
		} 
	}
}

/**
 * @desc 附件初始化
 * @param parentNodeId
 *            附件列表id
 * @param businessId
 *            业务id
 * @param buttonId
 *            按键id
 * @returns
 */
function attachFileInit(parentNodeId, businessId, buttonId) {
	if (businessId != undefined && businessId != "") {
		$.ajax({
			type : 'POST',
			url : "upload_loadFileList.do?parentNodeId=" + parentNodeId
					+ "&businessId=" + businessId,
			data : {},
			dataType : "json",
			cache : false,
			success : callbackAddList,
			error : DWZ.ajaxError
		});
	}
	if (buttonId != undefined) {
		$("#" + buttonId, navTab.getCurrentPanel()).bind(
				'click',
				function() {
					$.pdialog.open("upload_openWindow.do?parentNodeId="
							+ parentNodeId, "upload", "附件上传", {
						height : 320,
						width : 440,
						minH : 80,
						minW : 50,
						total : 20,
						max : false,
						mask : false,
						resizable : true,
						drawable : true,
						maxable : true,
						minable : true,
						fresh : true
					});
				});
	}

}
function callbackAddList(data) {
	data = DWZ.jsonEval(data);
	parentNodeId = data.parentNodeId;
	attachFileList = data.attachFileList;
	$.each(attachFileList, function(i, cdata) {
		addAttachtoTable(parentNodeId, cdata);
	});

}
/**
 * @desc 向附件列表中添加附件
 * @param parentNodeId
 *            列表Id
 * @param cdata
 *            数据
 * @returns
 */
function addAttachtoTable(parentNodeId, cdata) {
	var parentNode = $('#' + parentNodeId);
	var editEnable = parentNode.attr('editEnable');
	var fileId = cdata.fileId || cdata.attachFileId;
	var fileName = cdata.fileName || cdata.attachFileName;
	var status = cdata.status;
	var tmpFile = true;
	if (status != undefined) {
		tmpFile = false;
	}
	var html = '<tr><td>';
	html += '<a target=_blank href=upload_getFile.do?tmpFile=' + tmpFile
			+ '&fileId=' + fileId + '&fileName=' + fileName + '>' + fileName
			+ '</a>';
	html += '<input type=hidden name=attachFileId value="' + fileId
			+ '"></input>';
	html += '<input type=hidden name=attachFileName value="' + fileName
			+ '"></input>';
	html += '</td>';
	if (status != undefined) {
		html += '<input type=hidden name=status value="' + status
				+ '"></input>';
	}
	if (editEnable == "true") {
		html += '<td><img src="uploadify/cancel.png" border="0" alt="删除" onclick="delAttachFile(this)"></img><td>';
	}
	html += '</tr>';
	parentNode.append(html);
}
/**
 * @desc 附件上传成功回调
 * @param event
 * @param queueId
 * @param fileObj
 * @param response
 * @param data
 */
function fileUploadSucc(event, queueId, fileObj, response, data) {
	response = DWZ.jsonEval(response);
	// alert($('#attachFileInput').attr('parentNodeId'));
	// alert(response.fileId+","+response.fileName);
	var parentNodeId = $('#attachFileInput').attr('parentNodeId');
	addAttachtoTable(parentNodeId, response);
}
/**
 * @desc 附件删除
 * @param ctrl
 */
function delAttachFile(ctrl) {
	ctrl = $(ctrl);
	var parentTr = ctrl.parent().parent();
	var status = $("input[name=status]", parentTr).val();
	if (status == undefined) {
		parentTr.remove();
	} else {
		$("input[name=status]", parentTr).val("D");
		parentTr.attr('style', 'display:none');
	}
}
/**
 * @desc 提交前对list节点重命名,添加下标供后台以list形式接收
 * @param panel
 *            当面页面
 */
function reNameListNode(panel) {
	$(".dataTable",panel)
			.each(
					function(i, table) {
						table = $(table);
						var tmpPrex = table.attr("datalist");
						var filetype = table.attr("filetype");
						if (table.is('table')) {
							table = $("tbody", table);
						}
						table.children().each(
										function(j, chd) {
											chd = $(chd);
											if (filetype != undefined) {
												chd.append('<input type=hidden name=fileType value='
																+ filetype
																+ '></input>');
											}
											$("input,select,textarea", chd)
													.each(
															function(m, ctrl) {
																if (ctrl.type!='radio'&&ctrl.name.indexOf(tmpPrex) < 0) {
																	ctrl.name = tmpPrex
																			+ "["
																			+ j
																			+ "]."
																			+ ctrl.name;
																}
															});
										});
					});
}

/**
 * @desc 简历导出
 * @param resumeId
 */
function export_word(resumeId) {
	if (!$.browser.msie) {
		alert("请使用ie浏览器导出。");
		return;
	}
	try {
		var oWD = new ActiveXObject("Word.Application");
		var oDC = oWD.Documents.Add("", 0, 1);
		var oRange = oDC.Range(0, 1);
		var sel = document.body.createTextRange();
		var table = document.getElementById(resumeId);
		sel.moveToElementText(table);
		sel.select();
		sel.execCommand("Copy");
		oRange.Paste();
		oWD.Application.Visible = true;
	} catch (e) {
		alert("导出发生异常：" + e.name + "->" + e.description);
	}
}
/**
 * @desc excel导出
 * @param resumeId
 */
function export_xls(tableid, tablename) {
	if (!$.browser.msie) {
		alert("请使用ie浏览器导出。");
		return;
	}
	try {
		var exApp = new ActiveXObject("Excel.Application");
		var exWB = exApp.WorkBooks.add();
		var exSheet = exApp.ActiveWorkBook.WorkSheets(1);
		exSheet.name = tablename || "Sheet1";
		var sel = document.body.createTextRange();
		var table = document.getElementById(tableid);
		sel.moveToElementText(table);
		sel.select();
		sel.execCommand("Copy");
		exSheet.Paste();
		exApp.Application.Visible = true;
	} catch (e) {
		alert("导出发生异常：" + e.name + "->" + e.description);
	}
}